package bb.lanxing.lib.devices.utils;

import bb.lanxing.lib.devices.api.DeviceManager;
import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.base.XZDeviceManager;
//import bb.lanxing.lib.devices.bici.BiciController;
import bb.lanxing.lib.devices.bici.BiciController;
import bb.lanxing.lib.devices.ble.battery.BatteryController;
import bb.lanxing.lib.devices.ble.ble.interfaces.BodySensorLocationController;
import bb.lanxing.lib.devices.ble.ble.interfaces.SensorLocationController;
import bb.lanxing.lib.devices.ble.heartrate.HeartRateBeltController;
import bb.lanxing.lib.devices.ble.light.LightDeviceController;
import bb.lanxing.lib.devices.ble.switchablecadence.SwitchableCadenceController;
import bb.lanxing.lib.devices.ble.x1.X1Controller;
import bb.lanxing.lib.devices.cad01.Cadence01Controller;
import bb.lanxing.lib.devices.core.utils.DeviceHelper;
import bb.lanxing.lib.devices.heartrate01.HeartRate01Controller;
import bb.lanxing.lib.devices.sprint.SprintDeviceManager;
import bb.lanxing.lib.devices.sprint.XossDeviceController;
//import bb.lanxing.lib.devices.sprint.HeartRateBeltX2PController;
//import bb.lanxing.lib.devices.sprint.SprintDeviceManager;
//import bb.lanxing.lib.devices.sprint.XossDeviceController;
import java.util.Collections;
import java.util.List;

public class DeviceManagerHelper {
    public static String getDeviceAddressByType(int i) {
        List<SmartDevice> devicesByType;
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (deviceManager == null || (devicesByType = DeviceHelper.getDevicesByType(i)) == null || devicesByType.isEmpty()) {
            return null;
        }
        Collections.reverse(devicesByType);
        for (SmartDevice smartDevice : devicesByType) {
            String address = smartDevice.getAddress();
            if (deviceManager.isConnected(address)) {
                return address;
            }
        }
        return devicesByType.get(0).getAddress();
    }

    public static X1Controller getX1Controller() {
        DeviceManager deviceManager;
        String deviceAddressByType = getDeviceAddressByType(5);
        if (deviceAddressByType == null || (deviceManager = DeviceHelper.getDeviceManager()) == null || !(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        return ((XZDeviceManager) deviceManager).getX1Controller(deviceAddressByType);
    }

    public static XossDeviceController getXossDeviceController(String str) {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (deviceManager == null || !(deviceManager instanceof SprintDeviceManager)) {
            return null;
        }
        return ((XZDeviceManager) deviceManager).getXossDeviceController(str);
    }

    public static XossDeviceController getXossDeviceController() {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (deviceManager == null || !(deviceManager instanceof SprintDeviceManager)) {
            return null;
        }
        return ((XZDeviceManager) deviceManager).getXossDeviceController(getDeviceAddressByType(9));
    }

    public static BiciController getBiciController() {
        DeviceManager deviceManager;
        String deviceAddressByType = getDeviceAddressByType(1);
        if (deviceAddressByType == null || (deviceManager = DeviceHelper.getDeviceManager()) == null || !(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        return ((XZDeviceManager) deviceManager).getBiciController(deviceAddressByType);
    }

    public static HeartRateBeltController getHeartRateBeltController() {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (deviceManager == null || !(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        String deviceAddressByType = getDeviceAddressByType(16);
        if (deviceAddressByType != null || (deviceAddressByType = getDeviceAddressByType(3)) != null) {
            return ((XZDeviceManager) deviceManager).getHeartRateBeltController(deviceAddressByType);
        }
        return null;
    }

    public static SwitchableCadenceController getSwitchableCadenceController() {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (!(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        String deviceAddressByType = getDeviceAddressByType(SmartDevice.TYPE_VORTEX_CADENCE);
        if (deviceAddressByType != null || (deviceAddressByType = getDeviceAddressByType(SmartDevice.TYPE_VORTEX_CADENCE)) != null) {
            return ((XZDeviceManager) deviceManager).getSwitchableCadenceController(deviceAddressByType);
        }
        return null;
    }

    public static Cadence01Controller getCadence01Controller() {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (!(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        String deviceAddressByType = getDeviceAddressByType(SmartDevice.TYPE_CADENCE01);
        if (deviceAddressByType != null || (deviceAddressByType = getDeviceAddressByType(SmartDevice.TYPE_CADENCE01)) != null) {
            return ((XZDeviceManager) deviceManager).getCadence01Controller(deviceAddressByType);
        }
        return null;
    }

    public static HeartRate01Controller getHeartRate01Controller() {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (!(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        String deviceAddressByType = getDeviceAddressByType(SmartDevice.TYPE_HEART_RATE01);
        if (deviceAddressByType != null || (deviceAddressByType = getDeviceAddressByType(SmartDevice.TYPE_HEART_RATE01)) != null) {
            return ((XZDeviceManager) deviceManager).getHeartRate01Controller(deviceAddressByType);
        }
        return null;
    }

    /*public static HeartRateBeltX2PController getHeartRateBeltX2PController(String str) {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (deviceManager == null || !(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        return ((XZDeviceManager) deviceManager).getHeartRateBeltX2Controller(str);
    }*/

    public static HeartRateBeltController getHeartRateBeltController(String str) {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (deviceManager == null || !(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        return ((XZDeviceManager) deviceManager).getHeartRateBeltController(str);
    }

    public static BodySensorLocationController getBodySensorController(String str) {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (deviceManager == null || !(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        return ((XZDeviceManager) deviceManager).getBodySensorLocationController(str);
    }

    public static SensorLocationController getSensorLocationController(String str) {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (deviceManager == null || !(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        return ((XZDeviceManager) deviceManager).getSensorLocationController(str);
    }

    public static LightDeviceController getLightDeviceController(String str) {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (deviceManager == null || !(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        return ((XZDeviceManager) deviceManager).getLightDeviceController(str);
    }

    public static BatteryController getBatteryController(String str) {
        DeviceManager deviceManager = DeviceHelper.getDeviceManager();
        if (deviceManager == null || !(deviceManager instanceof XZDeviceManager)) {
            return null;
        }
        return ((XZDeviceManager) deviceManager).getBatteryController(str);
    }
}
